package week2

import "fmt"

type MyError struct{
	Msg string
	File string
	Line int
}
func (e MyError) Error() string {
	return fmt.Sprintf("%s:%d: %s",e.File, e.Line, e.Msg)
}
func test() error{
	return &MyError{"错误信息", "错误文件", 1}
}
func T4(){
	err := test()
	//因为是自定义类型,需要 switch type 断言
	switch err := err.(type) {
	case nil:
	case *MyError:
		fmt.Println("error occurred on line ", err.Line)
	default:
		//unknown error
	}
}